export default {
  namespaced: true, // 启用命名空间
  state: {
    mediaSwitch: true,
    ratingInfos: [],
    selectedPlatforms: [],
    // 新增：存储优势和改进项数据
    strengths: [], // Top 5 strengths数据
    improvements: [], // Top 5 areas for improvement数据
  },
  getters: {
    // 获取选中的平台
    selectedPlatforms: (state) => state.selectedPlatforms,
    // 可以添加更多getter
    isMediaOn: (state) => state.mediaSwitch,
    ratingCount: (state) => state.ratingInfos.length,
    strengths: (state) => state.strengths, // 新增
    improvements: (state) => state.improvements, // 新增
  },
  mutations: {
    // 更新媒体开关状态
    updateSwitchState(state, value) {
      state.mediaSwitch = value;
    },
    // 设置评分信息
    SET_RATING_INFOS(state, payload) {
      state.ratingInfos = payload;
    },
    // 设置选中的平台
    SET_SELECTED_PLATFORMS(state, platforms) {
      state.selectedPlatforms = platforms;
    },
    SET_STRENGTHS(state, data) {
      state.strengths = data; // 直接存原始数据（包括null/undefined）
    },
    SET_IMPROVEMENTS(state, data) {
      state.improvements = data;
    },
    // 清空所有状态（如果需要）
    CLEAR_ALL_STATE(state) {
      state.mediaSwitch = true;
      state.ratingInfos = [];
      state.selectedPlatforms = [];
      // 新增：清空优势和改进项数据
      state.strengths = [];
      state.improvements = [];
    },
  },
  actions: {
    // 更新选中的平台
    updateSelectedPlatforms({ commit }, platforms) {
      commit("SET_SELECTED_PLATFORMS", platforms);
      console.log("vuex中home存储的平台名", platforms);
    },
    // 可以添加更多action
    toggleMediaSwitch({ commit, state }) {
      commit("updateSwitchState", !state.mediaSwitch);
    },
    // 异步加载评分信息示例
    async loadRatingInfos({ commit }) {
      // const ratings = await api.getRatings();
      // commit('SET_RATING_INFOS', ratings);
    },
    // 新增：更新优势数据
    updateStrengths({ commit }, data) {
      commit("SET_STRENGTHS", data);
    },
    // 新增：更新改进项数据
    updateImprovements({ commit }, data) {
      commit("SET_IMPROVEMENTS", data);
    },
  },
};
